import {OutboundDeliveryOrder} from "../type/OutboundDeliveryOrder";
import {ClientInfo} from "../type/ClientInfo";
import LogFactory from "log/LogFactory";
import {EngineInfo} from "../type/EngineInfo";

/**
 * 出库单数据转换类
 */
class OdoDataConvert{
    private log = LogFactory.getLog("OdoDataConvert") ;
    private readonly data: OutboundDeliveryOrder[] ;
    private readonly convertMap = new Map<number,string>() ;
    /**
     * 构造函数
     * @param data 出库单数据
     */
    public constructor(data: OutboundDeliveryOrder[]) {
        this.data = data ;
    }
    public convertClient(client: ClientInfo[]) {
        client.forEach(c => {
            this.convertMap.set(c.id,c.clientName) ;
        }) ;
    }
    public convertEngine(engine: EngineInfo[]) {
        engine.forEach(e => {
            this.convertMap.set(e.id,e.engineSerial) ;
        }) ;
    }

    /**
     * 转换出库单数据
     */
    public convert() {
        this.data.forEach(o => {
            let temp = this.convertMap.get(Number.parseInt(o.odoFlow)) ;
            o.odoFlow = temp ? temp : o.odoFlow ;
        }) ;
    }

}

export default OdoDataConvert;